<template>
  <base-btn
    :title="title"
    @submit="leaveAMessage"
    :type="type"
    @resetForm="resetForm"
  >
    <el-input
      v-model="LAMValue"
      type="textarea"
      :autosize="{ minRows: 4, maxRows: 8 }"
      placeholder="请输入备注/意见"
      style="margin: 20px 0"
    >
    </el-input>
  </base-btn>
</template>
<script>
import api from "@/api/index";
import BaseBtn from "@/components/workflows/baseBtn";
import workManagement from "@/api/workManagement/index";
export default {
  components: { BaseBtn },
  props: {
    id: {
      type: Number,
      default: 0
    },
    title: {
      type: String,
      default: "留言"
    },
    type: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      LAMValue: ""
    };
  },
  methods: {
    // 留言
    leaveAMessage(callback) {
      if (this.LAMValue == "") {
        this.$message.error("请填写留言");
        return true;
      }
      let data = {
        suggestion: this.LAMValue
      };
      if (this.title == "留言") {
        api.WOLeaveAMessage(this.id, data).then(res => {
          this.msgSuccess("留言成功!");
          this.$emit("reload");
          callback && callback();
        });
      } else if (this.title == "强制关闭工单") {
        workManagement.toClose(this.id, data).then(res => {
          this.msgSuccess("处理成功！");
          this.$emit("reload");
          callback && callback();
        });
      } else {
        workManagement.toRetreat(this.id, data).then(res => {
          this.msgSuccess("撤回成功!");
          this.$emit("reload");
          callback && callback();
        });
      }
    },
    resetForm() {
      this.LAMValue = "";
    }
  }
};
</script>
